package com.lf.controller;


import com.lf.model.EbProductCategory;
import com.lf.service.ProductCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/product_category")
public class ProductCategoryController {

    @Autowired
    private ProductCategoryService product_categoryService;

    @RequestMapping("/list")
    public ModelAndView list(@RequestParam(value = "page", defaultValue = "1") int page,
                             @RequestParam(value = "pageSize", defaultValue = "3") int pageSize){
            //1.获取新闻表的第1页数据，每页3条
            List<EbProductCategory> product_categories = product_categoryService.list(page, pageSize);
            int maxPage = product_categoryService.getMaxPage(pageSize);
            //2.将数据(list)和视图(jsp)返回给spring mvc中央控制
            ModelAndView mv = new ModelAndView();
            //绑定数据
            mv.addObject("product_categories", product_categories);//key-value
            mv.addObject("curPage", page);

            mv.addObject("maxPage", maxPage);
            //绑定视图
            mv.setViewName("manage/productClass");
            return mv;
        }
    }